package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsAccountTraceMapper;
import com.qf.pojo.DtsAccountTrace;
import com.qf.pojo.DtsRegion;
import com.qf.service.DtsAccountTraceService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author YDW
 * projectName:shop-manage
 * time:2022/5/24 10:05
 * description:
 */
@Service
public class DtsAccountTraceServiceImpl implements DtsAccountTraceService {

    @Autowired
    DtsAccountTraceMapper accountTraceMapper;

    @Override
    public IPage<DtsAccountTrace> queryPage(Integer page, Integer limit, String sort, String order, String mobile, String username) {
        IPage<DtsAccountTrace> ipage=new Page<>(page,limit);
        QueryWrapper qw=new QueryWrapper<>();
        if(!StringUtils.isEmpty(mobile)){
            qw.like("mobile",mobile);
        }
        if(!StringUtils.isEmpty(username)){
            qw.like("id",username);
        }

        if(!StringUtils.isEmpty(sort)&&!StringUtils.isEmpty(order)){
            if(order.equals("desc")){
                qw.orderByDesc(sort);
            }else {
                qw.orderByAsc(sort);
            }
        }
        accountTraceMapper.selectPage(ipage, qw);
        return ipage;
    }

    @Override
    public Object approve(DtsAccountTrace accountTrace) {
        accountTraceMapper.updateById(accountTrace);
        return ResponseUtil.ok();
    }
}
